package edu.ubbcs.rs.backend.service.filter.manager;

import edu.ubbcs.rs.backend.model.Role;
import edu.ubbcs.rs.backend.service.filter.Filter;
import java.util.List;
import static javafx.scene.input.KeyCode.T;

/**
 * @author Merli Andras-Bertalan
 * @version 1.0
 * @created 09-jan.-2015 15:37:43
 */
public class FilterByRoleIterator implements FilterIterator {

    private final List<Filter> filters;
    private int current;
    private final Role role;

    public FilterByRoleIterator(List<Filter> filters, Role role) {
        this.role = role;
        this.filters = filters;
        current = -1;
    }

    @Override
    public boolean hasNext() {
        return current < filters.size()-1;
    }

    @Override
    public Filter next() {
        if (hasNext()) {
            current++;
            Filter filter = filters.get(current);
            if (Role.GUEST.equals(role) && (filter.getClass().getName().contains("Name") || filter.getClass().getName().contains("Event"))) {
                return next();
            } else {
                return filter;
            }
        }
        return null;
//        if (!hasNext()) {
//            throw new NoSuchElementException();
//        }
//        return filters.get(current++);
    }

}
